//
//  HDBageButton.m
//  youthNote
//
//  Created by huangrensheng on 16/1/29.
//  Copyright © 2016年 laber. All rights reserved.
//

#import "HDBageButton.h"

@interface HDBageButton()

@property (nonatomic, strong) UIButton *badge;

@end

@implementation HDBageButton

- (instancetype)init{
    if ([super init]) {
        self.badge = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.badge setBackgroundColor:[UIColor redColor]];
        [self.badge setTitle:@"1" forState:UIControlStateNormal];
        [self.badge setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.badge.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
        [self addSubview:self.badge];
        [self.badge.layer setCornerRadius:8];
        [self.badge.layer setBorderWidth:1.0f];
        [self.badge.layer setBorderColor:[UIColor redColor].CGColor];
         self.badge.backgroundColor = [UIColor redColor];
        
        [self.badge mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@16);
            make.height.equalTo(@16);
            make.top.equalTo(self.mas_top).equalTo(@4);
            make.right.equalTo(self.mas_right).equalTo(@(-4));
        }];
    }
    return self;
}

- (void)setBageValue:(NSString *)bageValue{
    [self.badge setTitle:bageValue forState:UIControlStateNormal];
    [self.badge mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(bageValue.length*(16-bageValue.length)));
    }];
}

- (void)awakeFromNib{
    
}

@end
